//
//  ApprovalRecordCell.swift
//  HuaYun
//
//  Created by enghou on 2018/7/13.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

import UIKit

class ApprovalRecordCell: UITableViewCell {

    @IBOutlet private weak var leading: NSLayoutConstraint!
    
    private var _model: JSON?
    
    @IBOutlet weak var spLabel: UILabel!
    
    @IBOutlet weak var approvalStatusLbl: UILabel!
    
    @IBOutlet var colorBlocks: [UIView]!
    
    
    
    @IBOutlet weak var nameLeading: NSLayoutConstraint!
    var model: JSON? {
        
        set{
            
            _model = newValue
            if let notagree = _model?.contents?["approvalResult"]?.int {
                if notagree == 0 {
                    for item in colorBlocks {
                        item.backgroundColor = UIColor.mainColor
                    }
                } else {
                    for item in colorBlocks {
                        item.backgroundColor = UIColor.hex("f13c3c")
                    }
                }
            } else {
                for item in colorBlocks {
                    item.backgroundColor = UIColor.mainColor
                }
            }
            
            approvalTimeLbl.text = _model?.contents?["createTime"]?.rawString()
            
            approvalStatusLbl.text = _model?.contents?["currentStepVal"]?.rawString()
            
            if (approvalStatusLbl.text?.count ?? 0) == 0 {
                leading.constant = 0
            } else {
                leading.constant = 20
            }
            
            approvalContentLbl.text = _model?.contents?["approvalOpinion"]?.rawString()
            
            if _model?.contents?["createUserVal"]?.rawString() != nil {
                approvalManagerNameLbl.text = _model?.contents?["createUserVal"]?.rawString()
            } else if _model?.contents?["approverName"]?.rawString() != nil {
                approvalManagerNameLbl.text = _model?.contents?["approverName"]?.rawString()
            }
            
            if let spname = _model?.contents?["spname"]?.rawString() {
                spLabel.text = spname
                nameLeading.constant = 10
            }
        }
        
        get{
            return _model
        }
    }
    
    
    @IBOutlet weak var approvalManagerNameLbl: UILabel!
    
    @IBOutlet weak var approvalTimeLbl: UILabel!
    
    @IBOutlet weak var approvalContentLbl: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
